package com.example.getextra;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {
    private TextView tv_account,tv_password;
    private Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        tv_account = findViewById(R.id.tv_account);
        tv_password = findViewById(R.id.tv_password);
        Intent intent = getIntent();
        String str1 = intent.getStringExtra(("account"));
        String str2 = intent.getStringExtra(("password"));
        tv_account.setText(str1);
        tv_password.setText(str2);
        btn = findViewById(R.id.btn);
        btn.setOnClickListener(v->{
            if(!str1.isEmpty() && !str2.isEmpty())
            {
                Intent intent1 = new Intent();
                intent1.putExtra("main_date","已接收到账号和密码");
                setResult(2,intent1);
            }else{
                Toast.makeText(this, "账号或密码错误", Toast.LENGTH_SHORT).show();
            }
            finish();
        });
    }
}